package com.yvon.maple.cloud.web;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.yvon.maple.cloud.web.data.support.DefaultMetaObjectHandler;
import com.yvon.maple.cloud.web.filter.LoginUserFilter;
import com.yvon.maple.cloud.web.handler.HttpHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @author : Yvon
 * @since : 2021-07-20
 */
@Configuration
@ComponentScan
@Slf4j
public class CloudWebAutoConfig {

    @Bean
    public MetaObjectHandler metaObjectHandler() {
        return new DefaultMetaObjectHandler();
    }

    @Bean
    @ConditionalOnMissingBean(PasswordEncoder.class)
    public BCryptPasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

    @Bean
    @ConditionalOnMissingBean(LoginUserFilter.class)
    public LoginUserFilter loginUserFilter() {
        log.info("启动全局用户上下文过滤器...");
        return new LoginUserFilter();
    }

    @Bean
    @ConditionalOnMissingBean(HttpHandler.class)
    public HttpHandler httpHandler() {
        return new HttpHandler();
    }
}
